package com.tz.web.admbook;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tz.bean.Book;
import com.tz.bean.TzParams;
import com.tz.service.book.IBookService;

@RequestMapping("/admin/book")
@Controller
public class BookController {

	@Autowired
	private IBookService bookService;
	
	@RequestMapping("/list")
	public String courseList(TzParams params){
		return "book/list";
	}
	
	@RequestMapping("/template")
	public ModelAndView template(TzParams params){
		ModelAndView modelAndView = new ModelAndView();
		List<Book> books = bookService.listBooks(params);
		int count = bookService.count(params);
		modelAndView.setViewName("/book/template");
		modelAndView.addObject("books",books);
		modelAndView.addObject("count",count);
		return modelAndView;
	}
	
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		bookService.delete(params);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public String update(TzParams params){
		bookService.update(params);
		return "success";
	}
}
